*****************************************************************************
*			          Analysis Rallies by MSA in the US	       				*
*																			*			
* Author: 			Valentina Gonzalez Rostani		        				*
* Contact: 			mag384@pitt.edu              							*
* Date: 			August 19 2024   										*
* Version:			Stata 17 												*                                                                          
*																			*
*****************************************************************************
/*
This do-file:
- Creates table A13 using data collected for rallies, visits, and exposure to automation. 

Input:
- Data\Rally_Visits_MSA.dta

Output:
- Table 1: Trump's Campaign Strategy (Close election 5) [Table\Trump_high_close5.tex]
- Table A13: Trump's Campaing Strategy (Close election 10) [Table\Trump_high_close10.tex]
- Table A14: Trump's Campaing Strategy (Forecasting 2016) [Table\Trump_high_forec.tex]
- Table A12: Summary statistics of variables used in this study about Trump's campaign strategies: rallies [Table\US_rallies_descriptive.tex]
*/

*Defining Directory
cd "C:\Users\vgonz\Dropbox\Pitt\OneDrive for Business\Dissertation - Vale\Paper 2 - Political-Economic Polarization\Replication"

*Calling the data
use "Data\Rally_Visits_MSA.dta", clear 


//////////////////////////////////////
* Preparing Variables 
//////////////////////////////////////
{

global statesID AK AL AR AZ CA CO CT DC DE FL GA HI IA ID IL IN KS KY LA MA MD ME MI MN MO MS MT NC ND NE NH NJ NM NV NY OH OK OR PA RI SC SD TN TX UT VA VT WA WI WV WY




gen rallies_pop=(rallies/Population)*100000 // Relative to the population and by 100K individuals for easier interpretation. This allows for comparisons between areas or groups with different population sizes by standardizing the number of visits according to a common population size. 
gen visits_pop=(visited/Population)*100000
gen anti_pop=(anti/Population)*100000

gen high_pop_pop=(high_pop/Population) // Share of exposed workers 

lab var high_pop "Workers Exposed to Automation"
lab var Pop "Population"
lab var anti_pop "Hate Incidents Per 100K Pop"
lab var high_pop_pop "Workers Exposed to Automation"
lab var close_election "Close Elections"
}

//////////////////////////////////////
* Regression Analysis 
//////////////////////////////////////
{

// table 1: Trump's Campaign Strategy
{
gen interaction_pop5=high_pop_pop*close_election5
gen interaction2_pop5=high_pop_pop*close_election5
gen interaction3_pop5=high_pop_pop*anti_pop
gen interaction4_pop5=close_election5*anti_pop

lab var interaction_pop5 "Exposed x Close Elections"
lab var interaction2_pop5 "Exposed x Close Elections"
lab var interaction3_pop5 "Exposed x Hate Incidents"
lab var interaction4_pop5 "Hate Incidents x Close"
lab var close_election5 "Close Elections"


eststo clear

eststo: qui reg rallies_pop high_pop_pop close_election5  anti_pop $statesID , cluster(state_num)
eststo: qui reg rallies_pop high_pop_pop close_election5   interaction2_pop5  anti_pop $statesID ,cluster(state_num)
eststo: qui reg rallies_pop high_pop_pop close_election5   interaction3_pop5  anti_pop $statesID ,cluster(state_num)
eststo: qui reg rallies_pop high_pop_pop close_election5  interaction2_pop5 interaction3_pop5 interaction4_pop5  anti_pop $statesID   ,cluster(state_num)

esttab , replace label se title(Trump's Campaing Strategy \label {TableRallies})  mti("Simple" "Close" "Hate" "All")  compress nogap star(* 0.1 ** 0.05 *** 0.01) b(%6.3f) keep(high* anti_pop close_election* interaction*) scalars( "N Observations" "r2 R$^2$" "aic AIC" )  indicate("FE State = *AK") 

esttab using "Table\Trump_high_close5.tex", replace label se title(Trump's Campaing Strategy \label {TableRallies})  mti("Simple" "Close" "Hate" "All")   compress nogap star(* 0.1 ** 0.05 *** 0.01) b(%6.3f) keep(high* anti_pop close_election* interaction*)  indicate("FE State = *AK" ) scalars( "N Observations" "r2 R$^2$" "aic AIC" )


}

// table A13: Trump's Campaing Strategy (Close election 10)
{
gen interaction_pop=high_pop_pop*close_election
gen interaction2_pop=high_pop_pop*close_election
gen interaction3_pop=high_pop_pop*anti_pop
gen interaction4_pop=close_election*anti_pop


lab var interaction_pop "Exposed x Close Elections"
lab var interaction2_pop "Exposed x Close Elections"
lab var interaction3_pop "Exposed x Hate Incidents"
lab var interaction4_pop "Hate Incidents x Close"


eststo clear

eststo: qui reg rallies_pop high_pop_pop close_election  anti_pop $statesID , cluster(state_num)
eststo: qui reg rallies_pop high_pop_pop close_election interaction2_pop  anti_pop $statesID ,cluster(state_num)
eststo: qui reg rallies_pop high_pop_pop close_election   interaction3_pop  anti_pop $statesID ,cluster(state_num)
eststo: qui reg rallies_pop high_pop_pop close_election  interaction2_pop interaction3_pop interaction4_pop  anti_pop $statesID ,cluster(state_num)

esttab , replace label se title(Trump's Campaing Strategy \label {TableRallies})  mti("Simple" "Close" "Hate" "All") compress nogap star(* 0.1 ** 0.05 *** 0.01) b(%6.3f) keep(high* anti_pop close_election interaction*) scalars( "N Observations" "r2 R$^2$" "aic AIC" )  indicate("FE State = *AK") 

esttab using "Table\Trump_high_close10.tex", replace label se title(Trump's Campaing Strategy (Close election 10) \label {TableRallies10})  mti("Simple" "Close" "Hate" "All")  compress nogap star(* 0.1 ** 0.05 *** 0.01) b(%6.3f) keep(high* anti_pop close_election* interaction*)  indicate("FE State = *AK" ) scalars( "N Observations" "r2 R$^2$" "aic AIC" )

}


//table A14: Trump's Campaing Strategy (Forecasting 2016)
{
gen interaction_pop_f=high_pop_pop*forescasting2
gen interaction2_pop_f=high_pop_pop*forescasting2
gen interaction3_pop_f=high_pop_pop*anti_pop
gen interaction4_pop_f=forescasting2*anti_pop

lab var interaction_pop_f "Exposed x Close Elections"
lab var interaction2_pop_f "Exposed x Close Elections"
lab var interaction3_pop_f "Exposed x Hate Incidents"
lab var interaction4_pop_f "Hate Incidents x Close"
lab var forescasting2 "Close Elections"

eststo clear

eststo: qui reg rallies_pop high_pop_pop forescasting2  anti_pop $statesID , cluster(state_num)
eststo: qui reg rallies_pop high_pop_pop forescasting2 interaction2_pop_f  anti_pop $statesID ,cluster(state_num)
eststo: qui reg rallies_pop high_pop_pop forescasting2   interaction3_pop_f  anti_pop $statesID ,cluster(state_num)
eststo: qui reg rallies_pop high_pop_pop forescasting2  interaction2_pop_f interaction3_pop_f interaction4_pop_f  anti_pop $statesID ,cluster(state_num)

esttab , replace label se title(Trump's Campaing Strategy \label {TableRallies})  mti("Simple" "Close" "Hate" "All")  compress nogap star(* 0.1 ** 0.05 *** 0.01) b(%6.3f) keep(high* anti_pop forescasting2 interaction*) scalars( "N Observations" "r2 R$^2$" "aic AIC" )   indicate("FE State = *AK") 

esttab using "Table\Trump_high_forec.tex", replace label se title(Trump's Campaing Strategy (Forecasting 2016) \label {TableRallies})  mti("Simple" "Close" "Hate" "All")  compress nogap star(* 0.1 ** 0.05 *** 0.01) b(%6.3f) keep(high* anti_pop forescasting2 interaction*)  indicate("FE State = *AK" ) scalars( "N Observations" "r2 R$^2$" "aic AIC" )

}
}

////////////////////////////////////
* Descriptives
///////////////////////////////////
{
lab var rallies "\# Rallies per MSA"
lab var visited "Visit MSA (dummy)"

lab var rallies_pop "\# Rallies relative to population"
lab var visits_pop "Visit (dummy) relative to population"

lab var close_election5 "Close election 2012 (5\%)"
lab var forescasting2 "Close election - Forecasting 2016"

lab var close_election "Close election 2012 (10\%)"
lab var anti "\# Hate incident per MSA"
lab var high_pop_pop "Workers Exposed to Automation (relative to pop.)"
lab var high "Workers Exposed to Automation (relative to MSA)"
lab var high_pop "\# Workers Exposed to Automation per MSA"

// table A12: Summary statistics of variables used in this study about Trump's campaign strategies: rallies
{
eststo clear

estpost sum rallies rallies_pop visited visits_pop high_pop high high_pop_pop  anti anti_pop close_election5 forescasting2 close_election, d

esttab , ///
	cells("mean(label(Mean) fmt(2)) p50(label(Median) fmt(2)) sd(label(S.D.) fmt(2)) min(label(Min.) fmt(2)) max(label(Max) fmt(2)) count(label(Obs.) fmt(0))") ///
	nonumber label replace noobs


esttab using "Table\US_rallies_descriptive.tex", ///
	cells("mean(label(Mean) fmt(2)) p50(label(Median) fmt(2)) sd(label(S.D.) fmt(2)) min(label(Min.) fmt(2)) max(label(Max) fmt(2)) count(label(Obs.) fmt(0))") ///
	nonumber label replace noobs
}
}
